<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <div id="app">
        总价格： {{total}}
        <p>商品名称--价格--数量</p>
        <ul>
            <li v-for="(p,index) of arr" :key="index">
                {{p.name}}-{{p.price}}--{{p.count}}
            </li>
        </ul>
        <button @click="jiayi()">杯子数量加一</button>
    </div>
    <script type="text/javascript">
        const Myapp = new Vue({
            el: "#app",
            data() {
                return {
                    arr: [{
                        name: '杯子',
                        price: 12.3,
                        count: 0
                    }, {
                        name: '牙刷',
                        price: 10,
                        count: 1
                    }]
                }
            },
            methods: {
                jiayi() {
                    this.arr[0].count++;
                }
            },
            computed: {
                total() {
                    let sum = 0;
                    for (let i = 0; i < this.arr.length; i++) {
                        sum += this.arr[i].price * this.arr[i].count;
                    }
                    return sum;
                }
            },
        })
    </script>
</body>

</html>